package com.test.daily.leetcode.y2022.m04.day0405;

/**
 * Solution
 *
 * @author Tom on 2022/4/5
 */
public class Solution {
    public static void main(String[] args) {
        Solution s = new Solution();
        System.out.println(s.countPrimeSetBits(10, 15));
    }
    public int countPrimeSetBits(int left, int right){
        int count = 0;
        for(int i = left; i <= right; i++){
            int num = Integer.bitCount(i);
            if(isPrime(num)) count++;
        }
        return count;
    }

    public boolean isPrime(int num){
        if(num == 1){
            return false;
        }
        if(num == 2 || num ==3){
            return true;
        }
        for(int i = 2; i <= Math.sqrt(num);i++){
            if(num%i == 0) return false;
        }
        return true;
    }
}
